import { createI18n } from 'vue-i18n'
import mZhLocale from './lang/zh.ts'
import mEnLocale from './lang/en.ts'
import { useAppStore } from '@/store/app.ts'
// 循环引用 pinia 创建之前报错 Are you trying to use a store before calling "app.use(pinia)"
import piniaInJs from '@/store/pixi.ts'

const messages = {
  en: {
    msg: {
      ...mEnLocale
    }
  },
  zh: {
    msg: {
      ...mZhLocale
    }
  }
}

/**
 * 返回当前 lang
 */
function getLanguage() {
  let appStore= useAppStore(piniaInJs)
  return appStore.language
  // return zh'
}

const i18n = createI18n({
  // 使用 Composition API 模式，则需要将其设置为false
  legacy: false,
  // 全局注入 $t 函数
  globalInjection: true,
  locale: getLanguage(),
  warnHtmlMessage: false,
  messages
})

export default i18n

/*
export default async (app) => {
  let appStore = useAppStore()
  let lang = appStore.language

  const i18n = createI18n({
    // 使用 Composition API 模式，则需要将其设置为false
    legacy: false,
    // 全局注入 $t 函数
    globalInjection: true,
    locale: lang,
    warnHtmlMessage: false,
    messages
  })
  app.use(i18n)
  return i18n;
}
*/
